package ua.races.kpiEpam;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;
import java.util.ResourceBundle;

public class Race {
    private static long count = 0;
    private long idRace;
    //private int capacity;
    private String stadium;
    //private Horse[] horseRegister = new Horse[100];
    private ArrayList<Bid> bids = new ArrayList<Bid>();
    // private float winValue;

    Race(String stadium) {
        synchronized (Race.class) {
            count++;
            idRace=count;
        }
        this.stadium = stadium;
        //  if (capacity <= 5)
        //     this.capacity = capacity;
        //else
        //   this.capacity = 5;
    }

//    private void setHorses() {
//        Random r = new Random(42);
//        //for (int i = 0; i < capacity; i++)
//            horseRegister = Horse.values();
//    }

//    public int getCapacity() {
//        return capacity;
//    }

//    public void setCapacity(int capacity) {
//        this.capacity = capacity;
//    }


    public void setStadium(String stadium) {
        this.stadium = stadium;
    }

    public String getStadium() {
        return stadium;
    }

    public Race() {
        synchronized (Race.class) {
            count++;
            idRace=count;
        }
        ;
    }

    /**
     * @param b Bid which client wants to add
     */

    public void addBid(Bid b) {
        this.bids.add(b);
    }

    /**
     * totalBidValue returns summed-up value
     * of all bids of the current race
     *
     * @return summed-up value of all bids (double)
     */

    public double totalBidValue() {
        double s = 0;
        Iterator<Bid> i;
        i = bids.listIterator();

        while (i.hasNext()) {
            s += i.next().getValue();
        }
        return s;
    }

    public void getInfo(ResourceBundle bundle) {
        System.out.println("---===---");
        System.out.println(bundle.getString("race.id") + " : "+ idRace);
        System.out.println(bundle.getString("race.stadium") +" : " + stadium);
        System.out.println(bundle.getString("race.totalBidValue") + " : " +totalBidValue());
//        bids.get(0).getInfo();
        System.out.println("---===---");

    }
}
